home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / archives / com / internet / sting / sting.lzh / STING / dev-kit / header / transprt.h < prev   
C/C++ Source or Header  |  1997-05-03  |  15KB  |  325 lines

  1. /*
  2.  *      transprt.h          (c) Peter Rottengatter  1996
  3.  *                              perot@pallas.amp.uni-hannover.de
  4.  *
  5.  *      Include this file to use functions from STinG.
  6.  *      i.e.: tcp, udp, etc ...
  7.  */
  8.  
  9. #ifndef STING_TRANSPRT_H
  10. #define STING_TRANSPRT_H
  11.  
  12.  
  13.  
  14. /*--------------------------------------------------------------------------*/
  15.  
  16.  
  17. /*
  18.  *   Data types used throughout STinG
  19.  */
  20.  
  21. typedef          char  int8;          /*   Signed  8 bit (char)             */
  22. typedef unsigned char uint8;          /* Unsigned  8 bit (byte, octet)      */
  23. typedef          int   int16;         /*   Signed 16 bit (int)              */
  24. typedef unsigned int  uint16;         /* Unsigned 16 bit (word)             */
  25. typedef          long  int32;         /*   Signed 32 bit                    */
  26. typedef unsigned long uint32;         /* Unsigned 32 bit (longword)         */
  27.  
  28.  
  29. #ifndef TRUE
  30. #define TRUE    1
  31. #endif
  32. #ifndef FALSE
  33. #define FALSE   0
  34. #endif
  35.  
  36.  
  37.  
  38. /*--------------------------------------------------------------------------*/
  39.  
  40.  
  41. /*
  42.  *   Driver access structure / functions
  43.  */
  44.  
  45. #define MAGIC   "STiKmagic"                 /* Magic for DRV_LIST.magic     */
  46. #define CJTAG   "STiK"
  47.  
  48.  
  49. typedef struct drv_header {                 /* Header part of TPL structure */
  50.     char *module;           /* Specific string that can be searched for     */
  51.     char *author;           /* Any string                                   */
  52.     char *version;          /* Format `00.00' Version:Revision              */
  53.  } DRV_HDR;
  54.  
  55.  
  56. typedef struct drv_list {
  57.     char      magic[10];                    /* Magic string, def'd as MAGIC */
  58.     DRV_HDR * cdecl (*get_dftab) (char *);  /* Get Driver Function Table    */
  59.     int16     cdecl (*ETM_exec) (char *);   /* Execute a STinG module       */
  60.     void      *cfg;                         /* Config structure             */
  61.     BASPAG    *sting_basepage;              /* STinG basepage address       */
  62.  } DRV_LIST;
  63.  
  64. extern DRV_LIST *drivers;
  65.  
  66.  
  67. #define get_dftab(x)    (*drivers->get_dftab)(x)
  68. #define ETM_exec(x)     (*drivers->ETM_exec)(x)
  69.  
  70.  
  71.  
  72. /*--------------------------------------------------------------------------*/
  73.  
  74.  
  75. #define TRANSPORT_DRIVER    "TRANSPORT_TCPIP"
  76. #define TCP_DRIVER_VERSION  "01.00"
  77.  
  78.  
  79. /*
  80.  *   TCP connection states
  81.  */
  82.  
  83. #define  TCLOSED       0    /* No connection.  Null, void, absent, ...      */
  84. #define  TLISTEN       1    /* Wait for remote request                      */
  85. #define  TSYN_SENT     2    /* Connect request sent, await matching request */
  86. #define  TSYN_RECV     3    /* Wait for connection ack                      */
  87. #define  TESTABLISH    4    /* Connection established, handshake completed  */
  88. #define  TFIN_WAIT1    5    /* Await termination request or ack             */
  89. #define  TFIN_WAIT2    6    /* Await termination request                    */
  90. #define  TCLOSE_WAIT   7    /* Await termination request from local user    */
  91. #define  TCLOSING      8    /* Await termination ack from remote TCP        */
  92. #define  TLAST_ACK     9    /* Await ack of terminate request sent          */
  93. #define  TTIME_WAIT   10    /* Delay, ensures remote has received term' ack */
  94.  
  95.  
  96. /*
  97.  *   Error return values
  98.  */
  99.  
  100. #define  E_NORMAL         0     /* No error occured ...                     */
  101. #define  E_OBUFFULL      -1     /* Output buffer is full                    */
  102. #define  E_NODATA        -2     /* No data available                        */
  103. #define  E_EOF           -3     /* EOF from remote                          */
  104. #define  E_RRESET        -4     /* Reset received from remote               */
  105. #define  E_UA            -5     /* Unacceptable packet received, reset      */
  106. #define  E_NOMEM         -6     /* Something failed due to lack of memory   */
  107. #define  E_REFUSE        -7     /* Connection refused by remote             */
  108. #define  E_BADSYN        -8     /* A SYN was received in the window         */
  109. #define  E_BADHANDLE     -9     /* Bad connection handle used.              */
  110. #define  E_LISTEN        -10    /* The connection is in LISTEN state        */
  111. #define  E_NOCCB         -11    /* No free CCB's available                  */
  112. #define  E_NOCONNECTION  -12    /* No connection matches this packet (TCP)  */
  113. #define  E_CONNECTFAIL   -13    /* Failure to connect to remote port (TCP)  */
  114. #define  E_BADCLOSE      -14    /* Invalid TCP_close() requested            */
  115. #define  E_USERTIMEOUT   -15    /* A user function timed out                */
  116. #define  E_CNTIMEOUT     -16    /* A connection timed out                   */
  117. #define  E_CANTRESOLVE   -17    /* Can't resolve the hostname               */
  118. #define  E_BADDNAME      -18    /* Domain name or dotted dec. bad format    */
  119. #define  E_LOSTCARRIER   -19    /* The modem disconnected                   */
  120. #define  E_NOHOSTNAME    -20    /* Hostname does not exist                  */
  121. #define  E_DNSWORKLIMIT  -21    /* Resolver Work limit reached              */
  122. #define  E_NONAMESERVER  -22    /* No nameservers could be found for query  */
  123. #define  E_DNSBADFORMAT  -23    /* Bad format of DS query                   */
  124. #define  E_UNREACHABLE   -24    /* Destination unreachable                  */
  125. #define  E_DNSNOADDR     -25    /* No address records exist for host        */
  126. #define  E_NOROUTINE     -26    /* Routine unavailable                      */
  127. #define  E_LOCKED        -27    /* Locked by another application            */
  128. #define  E_FRAGMENT      -28    /* Error during fragmentation               */
  129. #define  E_TTLEXCEED     -29    /* Time To Live of an IP packet exceeded    */
  130. #define  E_PARAMETER     -30    /* Problem with a parameter                 */
  131. #define  E_BIGBUF        -31    /* Input buffer is too small for data       */
  132. #define  E_LASTERROR      31    /* ABS of last error code in this list      */
  133.  
  134.  
  135.  
  136. /*--------------------------------------------------------------------------*/
  137.  
  138.  
  139. /*
  140.  *   IP packet header.
  141.  */
  142.  
  143. typedef  struct ip_header {
  144.     unsigned  version   : 4;    /* IP Version                               */
  145.     unsigned  hd_len    : 4;    /* Internet Header Length                   */
  146.     unsigned  tos       : 8;    /* Type of Service                          */
  147.     uint16    length;           /* Total of all header, options and data    */
  148.     uint16    ident;            /* Identification for fragmentation         */
  149.     unsigned  reserved  : 1;    /* Reserved : Must be zero                  */
  150.     unsigned  dont_frg  : 1;    /* Don't fragment flag                      */
  151.     unsigned  more_frg  : 1;    /* More fragments flag                      */
  152.     unsigned  frag_ofst : 13;   /* Fragment offset                          */
  153.     uint8     ttl;              /* Time to live                             */
  154.     uint8     protocol;         /* Protocol                                 */
  155.     uint16    hdr_chksum;       /* Header checksum                          */
  156.     uint32    ip_src;           /* Source IP address                        */
  157.     uint32    ip_dest;          /* Destination IP address                   */
  158.  } IP_HDR;
  159.  
  160.  
  161. /*
  162.  *   Internal IP packet representation.
  163.  */
  164.  
  165. typedef  struct ip_packet {
  166.     IP_HDR    hdr;              /* Header of IP packet                      */
  167.     void      *options;         /* Options data block                       */
  168.     int16     opt_length;       /* Length of options data block             */
  169.     void      *pkt_data;        /* IP packet data block                     */
  170.     int16     pkt_length;       /* Length of IP packet data block           */
  171.     uint32    timeout;          /* Timeout of packet life                   */
  172.     uint32    ip_gateway;       /* Gateway for forwarding this packet       */
  173.     void      *recvd;           /* Receiving port                           */
  174.     struct ip_packet  *next;    /* Next IP packet in IP packet queue        */
  175.  } IP_DGRAM;
  176.  
  177.  
  178. /*
  179.  *   Input queue structures
  180.  */
  181.  
  182. typedef struct ndb {        /* Network Data Block.  For data delivery       */
  183.     char        *ptr;       /* Pointer to base of block. (For KRfree();)    */
  184.     char        *ndata;     /* Pointer to next data to deliver              */
  185.     uint16      len;        /* Length of remaining data                     */
  186.     struct ndb  *next;      /* Next NDB in chain or NULL                    */
  187.  } NDB;
  188.  
  189.  
  190. /*
  191.  *   Connection information block
  192.  */
  193.  
  194. typedef struct cib {        /* Connection Information Block                 */
  195.     uint16      protocol;   /* TCP or UDP or ... 0 means CIB is not in use  */
  196.     uint16      lport;      /* TCP local  port     (ie: local machine)      */
  197.     uint16      rport;      /* TCP remote port     (ie: remote machine)     */
  198.     uint32      rhost;      /* TCP remote IP addr  (ie: remote machine)     */
  199.     uint32      lhost;      /* TCP local  IP addr  (ie: local machine)      */
  200.     uint16      status;     /* Net status. 0 means normal                   */
  201.  } CIB;
  202.  
  203.  
  204. /*
  205.  *   Values for protocol field
  206.  */
  207.  
  208. #define P_ICMP     1        /* IP assigned number for ICMP                  */
  209. #define P_TCP      6        /* IP assigned number for TCP                   */
  210. #define P_UDP     17        /* IP assigned number for UDP                   */
  211.  
  212.  
  213.  
  214. /*--------------------------------------------------------------------------*/
  215.  
  216.  
  217. /*
  218.  *   Transport structure / functions
  219.  */
  220.  
  221. typedef  struct tpl  {
  222.     char *     module;      /* Specific string that can be searched for     */
  223.     char *     author;      /* Any string                                   */
  224.     char *     version;     /* Format `00.00' Version:Revision              */
  225.     void *     cdecl  (* KRmalloc) (int32);
  226.     void       cdecl  (* KRfree) (void *);
  227.     int32      cdecl  (* KRgetfree) (int16);
  228.     void *     cdecl  (* KRrealloc) (void *, int32);
  229.     char *     cdecl  (* get_err_text) (int16);
  230.     char *     cdecl  (* getvstr) (char *);
  231.     int16      cdecl  (* carrier_detect) (void);
  232.     int16      cdecl  (* TCP_open) (uint32, int16, int16, uint16);
  233.     int16      cdecl  (* TCP_close) (int16, int16);
  234.     int16      cdecl  (* TCP_send) (int16, void *, int16);
  235.     int16      cdecl  (* TCP_wait_state) (int16, int16, int16);
  236.     int16      cdecl  (* TCP_ack_wait) (int16, int16);
  237.     int16      cdecl  (* UDP_open) (uint32, int16);
  238.     int16      cdecl  (* UDP_close) (int16);
  239.     int16      cdecl  (* UDP_send) (int16, void *, int16);
  240.     int16      cdecl  (* CNkick) (int16);
  241.     int16      cdecl  (* CNbyte_count) (int16);
  242.     int16      cdecl  (* CNget_char) (int16);
  243.     NDB *      cdecl  (* CNget_NDB) (int16);
  244.     int16      cdecl  (* CNget_block) (int16, void *, int16);
  245.     void       cdecl  (* housekeep) (void);
  246.     int16      cdecl  (* resolve) (char *, char **, uint32 *, int16);
  247.     void       cdecl  (* ser_disable) (void);
  248.     void       cdecl  (* ser_enable) (void);
  249.     int16      cdecl  (* set_flag) (int16);
  250.     void       cdecl  (* clear_flag) (int16);
  251.     CIB *      cdecl  (* CNgetinfo) (int16);
  252.     int16      cdecl  (* on_port) (char *);
  253.     void       cdecl  (* off_port) (char *);
  254.     int16      cdecl  (* setvstr) (char *, char *);
  255.     int16      cdecl  (* query_port) (char *);
  256.     int16      cdecl  (* CNgets) (int16, char *, int16, char);
  257.     int16      cdecl  (* ICMP_send) (uint32, uint8, uint8, void *, uint16);
  258.     int16      cdecl  (* ICMP_handler) (int16 cdecl (*) (IP_DGRAM *), int16);
  259.     void       cdecl  (* ICMP_discard) (IP_DGRAM *);
  260.  } TPL;
  261.  
  262. extern TPL *tpl;
  263.  
  264.  
  265. /*
  266.  *   Definitions of transport functions for direct use
  267.  */
  268.  
  269. #define KRmalloc(x)                      (*tpl->KRmalloc)(x)
  270. #define KRfree(x)                        (*tpl->KRfree)(x)
  271. #define KRgetfree(x)                     (*tpl->KRgetfree)(x)
  272. #define KRrealloc(x,y)                   (*tpl->KRrealloc)(x,y)
  273. #define get_err_text(x)                  (*tpl->get_err_text)(x)
  274. #define getvstr(x)                       (*tpl->getvstr)(x)
  275. #define carrier_detect()                 (*tpl->carrier_detect)()
  276. #define TCP_open(w,x,y,z)                (*tpl->TCP_open)(w,x,y,z)
  277. #define TCP_close(x,y)                   (*tpl->TCP_close)(x,y)
  278. #define TCP_send(x,y,z)                  (*tpl->TCP_send)(x,y,z)
  279. #define TCP_wait_state(x,y,z)            (*tpl->TCP_wait_state)(x,y,z)
  280. #define TCP_ack_wait(x,y)                (*tpl->TCP_ack_wait)(x,y)
  281. #define UDP_open(x,y)                    (*tpl->UDP_open)(x,y)
  282. #define UDP_close(x)                     (*tpl->UDP_close)(x)
  283. #define UDP_send(x,y,z)                  (*tpl->UDP_send)(x,y,z)
  284. #define CNkick(x)                        (*tpl->CNkick)(x)
  285. #define CNbyte_count(x)                  (*tpl->CNbyte_count)(x)
  286. #define CNget_char(x)                    (*tpl->CNget_char)(x)
  287. #define CNget_NDB(x)                     (*tpl->CNget_NDB)(x)
  288. #define CNget_block(x,y,z)               (*tpl->CNget_block)(x,y,z)
  289. #define CNgetinfo(x)                     (*tpl->CNgetinfo)(x)
  290. #define CNgets(w,x,y,z)                  (*tpl->CNgets)(w,x,y,z)
  291. #define housekeep()                      (*tpl->housekeep)()
  292. #define resolve(w,x,y,z)                 (*tpl->resolve)(w,x,y,z)
  293. #define ser_disable()                    (*tpl->ser_disable)()
  294. #define ser_enable()                     (*tpl->ser_enable)()
  295. #define set_flag(x)                      (*tpl->set_flag)(x)
  296. #define clear_flag(x)                    (*tpl->clear_flag)(x)
  297. #define on_port(x)                       (*tpl->on_port)(x)
  298. #define off_port(x)                      (*tpl->off_port)(x)
  299. #define setvstr(x,y)                     (*tpl->setvstr)(x,y)
  300. #define query_port(x)                    (*tpl->query_port)(x)
  301. #define ICMP_send(v,w,x,y,z)             (*tpl->ICMP_send)(v,w,x,y,z)
  302. #define ICMP_handler(x,y)                (*tpl->ICMP_handler)(x,y)
  303. #define ICMP_discard(x)                  (*tpl->ICMP_discard)(x)
  304.  
  305.  
  306.  
  307. /*--------------------------------------------------------------------------*/
  308.  
  309.  
  310. /*
  311.  *   Handler flag values.
  312.  */
  313.  
  314. #define  HNDLR_SET        0         /* Set new handler if space             */
  315. #define  HNDLR_FORCE      1         /* Force new handler to be set          */
  316. #define  HNDLR_REMOVE     2         /* Remove handler entry                 */
  317. #define  HNDLR_QUERY      3         /* Inquire about handler entry          */
  318.  
  319.  
  320.  
  321. /*--------------------------------------------------------------------------*/
  322.  
  323.  
  324. #endif /* STING_TRANSPRT_H */
  325.